package com.qst.repository;

import com.qst.pojo.entity.StationInventory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * 站点库存 Repository
 */
@Repository
public interface StationInventoryRepository extends JpaRepository<StationInventory, Integer> {
    
    /**
     * 根据站点ID查询库存列表（使用JPQL查询确保字段映射正确）
     */
    @Query("SELECT s FROM StationInventory s WHERE s.stationId = :stationId ORDER BY s.id DESC")
    List<StationInventory> findByStationIdNative(@Param("stationId") Integer stationId);
    
    /**
     * 根据站点ID查询库存列表
     */
    List<StationInventory> findByStationId(Integer stationId);
    
    /**
     * 根据站点ID和物品ID查询库存
     */
    Optional<StationInventory> findByStationIdAndItemId(Integer stationId, Integer itemId);
    
    /**
     * 删除站点的所有库存
     */
    void deleteByStationId(Integer stationId);
}